//package com.example.demo.sso;
//
//import org.jasig.cas.client.session.SingleSignOutFilter;
//import org.jasig.cas.client.validation.Cas30ServiceTicketValidator;
//import org.jasig.cas.client.validation.TicketValidator;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.authentication.AuthenticationManager;
//import org.springframework.security.authentication.ProviderManager;
//import org.springframework.security.cas.ServiceProperties;
//import org.springframework.security.cas.authentication.CasAuthenticationProvider;
//import org.springframework.security.cas.web.CasAuthenticationEntryPoint;
//import org.springframework.security.cas.web.CasAuthenticationFilter;
//import org.springframework.security.web.AuthenticationEntryPoint;
//import org.springframework.security.web.authentication.logout.LogoutFilter;
//import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
//
//@Configuration
//public class CasConfig {
//
//    @Value("${cas.server.url}")
//    private String casServerUrl;
//    @Value("${base.url}")
//    private String baseUrl;
//
//    @Bean
//    public AuthenticationEntryPoint authenticationEntryPoint() {
//        CasAuthenticationEntryPoint entryPoint = new CasAuthenticationEntryPoint();
//        entryPoint.setLoginUrl(casServerUrl + "/login");
//        entryPoint.setServiceProperties(this.serviceProperties());
//        return entryPoint;
//    }
//
//    @Bean
//    protected AuthenticationManager authenticationManager() throws Exception {
//        return new ProviderManager(this.casAuthenticationProvider());
//    }
//
//    @Bean
//    public CasAuthenticationFilter casAuthenticationFilter(
//            AuthenticationManager authenticationManager,
//            ServiceProperties serviceProperties) throws Exception {
//        CasAuthenticationFilter filter = new CasAuthenticationFilter();
//        filter.setAuthenticationManager(authenticationManager);
//        filter.setServiceProperties(serviceProperties);
//        return filter;
//    }
//
//    @Bean
//    public ServiceProperties serviceProperties() {
//        ServiceProperties serviceProperties = new ServiceProperties();
//        serviceProperties.setService(baseUrl + "/login/cas");
//        serviceProperties.setSendRenew(false);
//        return serviceProperties;
//    }
//
//    @Bean
//    public TicketValidator ticketValidator() {
//        return new Cas30ServiceTicketValidator(casServerUrl);
//    }
//
//    @Bean
//    public CasAuthenticationProvider casAuthenticationProvider() {
//        CasAuthenticationProvider provider = new CasAuthenticationProvider();
//        provider.setServiceProperties(this.serviceProperties());
//        provider.setTicketValidator(this.ticketValidator());
//        provider.setAuthenticationUserDetailsService(new CustomUserDetailsService());
//        provider.setKey("CAS_PROVIDER_LOCALHOST");
//        return provider;
//    }
//
//    @Bean
//    public SecurityContextLogoutHandler securityContextLogoutHandler() {
//        return new SecurityContextLogoutHandler();
//    }
//
//    @Bean
//    public LogoutFilter logoutFilter() {
//        LogoutFilter logoutFilter = new LogoutFilter(casServerUrl + "/logout?service=" + baseUrl,
//                securityContextLogoutHandler());
//        logoutFilter.setFilterProcessesUrl("/logout/cas");
//        return logoutFilter;
//    }
//
//    @Bean
//    public SingleSignOutFilter singleSignOutFilter() {
//        SingleSignOutFilter singleSignOutFilter = new SingleSignOutFilter();
//        singleSignOutFilter.setIgnoreInitConfiguration(true);
//        return singleSignOutFilter;
//    }
//}